<html>
<head>
  <meta charset="UTF-8">
  <meta name="layout" content="main"/>
  <title>TimeTracker Calendar</title>
  <r:require modules="timeTracker,chosen"/>
</head>
<body>
  <div id="cal"></div>
  <div id="timetracker"></div>
  <h1 id="timeTracker">Edit Time Tracker</h1>
  <g:flashMessage/>
    <g:hasErrors bean="${propertyName}">
    <g:each var="timeTrackerInstance" status="i" in="${timeTrackerList }">
    <ul class="errors" role="alert">
      <g:eachError bean="${timeTrackerInstance}" var="error">
      <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="\${error.field}"</g:if>><g:message error="\${error}"/></li>
      </g:eachError>
    </ul>
    </g:each>
    </g:hasErrors>
    <g:form class="rows">
    <table class="sortable tableForm timeTracker">
      <colgroup>
        <col><col>
      </colgroup>
      <thead>
        <tr>
          <th><g:message code='timeTracker.dateOfWork.label'  default= 'Date Of Work' /></th>
          <th><g:message code='timeTracker.hours.label'  default= 'Hours' /></th>
          <th><g:message code="timeTracker.project.label" default="Project" /></th>
          <th><g:message code="timeTracker.phase.label" default="Phase" /></th>
          <th><g:message code='timeTracker.comments.label'  default= 'Comments' /></th>
          <th><g:message code="timeTracker.issue.label" default="Issue" /></th>
          <th><g:message code="timeTracker.developmentTask.label" default="Development Task" /></th>
          <th><g:message code="timeTracker.developmentChecklist.label" default="Development Checklist" /></th>
          <th><g:message code="timeTracker.person.label" default="Person" /></th>
          <th></th>
        </tr>
      </thead>
      <tbody>
      <g:each var="timeTrackerInstance" status="i" in="${timeTrackerList }">
        <tr>
          <td><g:hiddenField name="timeTrackers[${i}].id" value="${timeTrackerInstance?.id }"/><g:jqDatePicker class="hasDatepicker" name="timeTrackers[${i}].dateOfWork" id="timeTrackers${i}dateOfWork" value="${timeTrackerInstance?.dateOfWork }"/><g:eachError bean="${timeTrackerInstance}" field="dateOfWork" var="error"><p class="form-help error"><g:message error="${error}" /></p></g:eachError></td>
          <td><g:textField name="timeTrackers[${i}].hours" value="${timeTrackerInstance?.hours }" class="hasHours"/><g:eachError bean="${timeTrackerInstance}" field="hours" var="error"><p class="form-help error"><g:message error="${error}" /></p></g:eachError></td>
          <td><g:ajaxSelect name="timeTrackers[${i}].project.id" from="${projectList}" optionKey="id" value="${timeTrackerInstance?.project?.id}" class="many-to-one chzn-select" noSelection="${['null':'Select One...']}" controller="issue" action="ajaxGetIssues" updateId="timeTrackers[${i}].issue.id"/><g:eachError bean="${timeTrackerInstance}" field="project" var="error"><p class="form-help error"><g:message error="${error}" /></p></g:eachError></td>
          <td><g:select name="timeTrackers[${i}].phase.id" from="${phaseList}" optionKey="id" value="${timeTrackerInstance?.phase?.id}" class="many-to-one"/><g:eachError bean="${timeTrackerInstance}" field="phase" var="error"><p class="form-help error"><g:message error="${error}" /></p></g:eachError></td>
          <td><g:textField  name="timeTrackers[${i}].comments" value="${timeTrackerInstance?.comments }" class="hasNotes"/><g:eachError bean="${timeTrackerInstance}" field="hours" var="error"><p class="form-help error"><g:message error="${error}" /></p></g:eachError></td>
          <td><g:ajaxSelect id="timeTrackers[${i}].issue.id" name="timeTrackers[${i}].issue.id" from="${timeTrackerInstance.project == null ? [] : edu.uow.devdocs.Issue.findAllByProject(timeTrackerInstance?.project,[cache: true])}" optionKey="id" value="${timeTrackerInstance?.issue?.id}" class="many-to-one" noSelection="${['null':'Select One...']}" controller="developmentTask" action="ajaxGetDevelopmentTasks" updateId="timeTrackers[${i}].developmentTask.id"/><g:eachError bean="${timeTrackerInstance}" field="issue" var="error"><p class="form-help error"><g:message error="${error}" /></p></g:eachError></td>
          <td><g:ajaxSelect name="timeTrackers[${i}].developmentTask.id" from="${timeTrackerInstance.project == null ? [] : edu.uow.devdocs.DevelopmentTask.findAllByProject(timeTrackerInstance?.project,[cache: true])}" optionKey="id" value="${timeTrackerInstance?.developmentTask?.id}" class="many-to-one" noSelection="${['null':'Select One...']}" controller="developmentChecklist" action="ajaxGetDevelopmentChecklists" updateId="timeTrackers[${i}].developmentChecklist.id" /><g:eachError bean="${timeTrackerInstance}" field="developmentTask" var="error"><p class="form-help error"><g:message error="${error}" /></p></g:eachError></td>
          <td><g:select name="timeTrackers[${i}].developmentChecklist.id" from="${timeTrackerInstance.developmentTask == null ? [] : edu.uow.devdocs.DevelopmentChecklist.findAllByDevelopmentTask(timeTrackerInstance?.developmentTask,[cache: true])}" optionKey="id" value="${timeTrackerInstance?.developmentChecklist?.id}" class="many-to-one" noSelection="${['null':'Select One...']}"/><g:eachError bean="${timeTrackerInstance}" field="developmentChecklist" var="error"><p class="form-help error"><g:message error="${error}" /></p></g:eachError></td>
          <td><g:select name="timeTrackers[${i}].person.id" from="${edu.uow.devdocs.Person.list()}" optionKey="id" value="${timeTrackerInstance?.person?.id}" noSelection="${['null':'Select One...']}" class="many-to-one"/><g:eachError bean="${timeTrackerInstance}" field="person" var="error"><p class="form-help error"><g:message error="${error}" /></p></g:eachError></td>
          <td><g:if test="${timeTrackerInstance.id }"><g:link action="deleteFromCalendar" params="['id':timeTrackerInstance.id,'date':params.date,'username':params.username ]">delete</g:link></g:if></td>
        </tr>
        </g:each>
      </tbody>
    </table>
    <fieldset class="form-actions">
      <g:actionSubmit class="save" action="updateTimeTrackerList" value="${message(code: 'default.button.update.label', default: 'Save')}" />
    </fieldset>
  </g:form>
  <div class="hidden">
    <div id="dragDlg">What would you like to do to the days events?</div>
  </div>
</body>
</html>